<?php
$pathArr = explode("/", $_SERVER["PHP_SELF"]);
$contextPath = $pathArr[1];
$rootPath = $_SERVER["DOCUMENT_ROOT"];

include $rootPath . "/" . $contextPath . "/apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();
$page = $_GET['page'];
if (!isset($page) && $page == "") {
	$page = 1;
}

$mode=$_GET['mode'];
if (isset($mode) && $mode == "search"){
	$recreationRoomNumber = $_GET['recreation_room_number'];
	$listRecreationRoom = $managerIUDS->listQueryLimit($page, "recreation_room", "recreation_room_id"," WHERE recreation_room_number = '".$recreationRoomNumber."'");
	}else {
	$listRecreationRoom = $managerIUDS->listQueryLimit($page, "recreation_room", "recreation_room_id","");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Pet List :.</title>
<?php
require_once("../includes/css_inc.php");
require_once("../includes/js_inc.php");
?>
<script>
			$(document).ready(function(){ 
				$(function() {
					$( "#combobox" ).combobox();
				});
				$("#recreation_room_number").autocomplete({
					source: function( request, response ) {
		                $.ajax({
							type: "GET",
							url: "../actions/recreation_room_action.php",
							data: {mode : "listRecreationRoomNumberData",recreation_room_number : $("#recreation_room_number").val()},
							contentType: "application/json; charset=utf-8", 
							dataType: "json",
		                    success: function( data ) {
			                        response( $.map( data, function( item ) {
			                            return {
			                                label: item.recreation_room_number,
			                                value: item.recreation_room_number
			                            }
			                        }));
		                    }
		                });
		            },
					minLength: 2
				});
			}); 
			function deleteRecreationRoomData(recreationRoomId) {
				if (confirm("Do you really want to delete?")) {
					window.location = "../actions/recreation_room_action.php?mode=delete&recreation_room_id=" + recreationRoomId;
				}
			}
		</script>
</head>
<body>
<form name="frm1" id="frm1" action="../actions/recreation_room_action.php" method="get">
	<table width="100%" border="0">
		<tr>
        	<td align="right">เลขที่ห้องพัก : 
        		<input type="text" name="recreation_room_number" id="recreation_room_number" class="higthInput"> 
				<input type="submit" value="ค้นหา"/>
			</td>
         </tr>
	</table>
	<input type="hidden" name="mode" id="mode" value="search">
</form>
<table style="width: 100%">
	<thead class="ui-widget">
		<tr class="ui-widget-header">
			<td width="2%" align="center">ลำดับ</td>
			<td width="3%" align="center">เลขที่ห้องพัก</td>
			<td width="10%" align="center">รายละเอียด</td>
			<td width="2%" align="center">น้ำหนัก</td>
			<td width="3%" align="center">ราคา/คืน</td>
			<td width="3%" align="center">สถานะ</td>
			<td width="3%" align="center">จองห้อง</td>
		</tr>
	</thead>
	<tbody class="ui-widget-content">
	<?php
	$i = $listRecreationRoom->startLimit;
	$r = 0;
	$i = ((($page*10)+1)-10);
	if(sizeof($listRecreationRoom) > 0){
		foreach ($listRecreationRoom as $value) {
			?>
		<tr>
			<td width="2%" align="center"><?=$i?></td>
			<td width="3%" align="center"><?=$value["recreation_room_number"]?></td>
			<td width="5%" align="center"><?=$value["recreation_room_detail"]?></td>
			<td width="5%" align="center"><?php
			if($value["recreation_room_limit_weight"] == "L"){
					echo "อาหารสำหรับสัตว์เลี้ยงน้ำหนักน้อยกว่า 25";
			}else{
					echo "อาหารสำหรับสัตว์เลี้ยงน้ำหนักมากกว่า 25";
			}
			?></td>
			<td width="-%" align="center"><?=$value["price"]?></td>
			<td width="5%" align="center">
			<?php
			$recreationRoomData = $managerIUDS->queryData("end_date", "booking", " WHERE recreation_room_id='".$value["recreation_room_id"]."'", "1", "");
			if($value["is_free"] == "Y"){
				echo 'ห้องว่าง';
			}else{
				echo 'ห้องเต็ม';
			}
			?>
			</td>
			<!--<td width="10%" align="center"><?=$value["species_name"]?></td>
           	   					<td width="20%" align="center"><?=$value["species_detail"]?></td>-->
			<td width="3%" align="center"><a
				href="booking_detail.php?mode=insert&recreation_room_id=<?=$value["recreation_room_id"];?>"><img
				class="ui-icon ui-icon-plusthick" title="booking" /></a></td>
		</tr>
		<?php
		$i++; $r++;}
	}else{
		?>
		<tr>
			<td colspan="9" align="center"><font size="2" color="red">Data
			Empty!!!</font></td>
		</tr>
		<?php
	}
	?>
		<tr>
			<td align="center" colspan="11"><?=$managerIUDS->buildPageBtn($page, $managerIUDS->getMaxPageByColumnName("recreation_room", "recreation_room_id"))?></td>
		</tr>
	</tbody>
</table>
</body>
</html>
